class Solution
{
public:
    vector<int> topStudents(vector<string> &positive_feedback, vector<string> &negative_feedback, vector<string> &report, vector<int> &student_id, int k)
    {
        unordered_set<string> pf(positive_feedback.begin(), positive_feedback.end());
        unordered_set<string> nf(negative_feedback.begin(), negative_feedback.end());

        int n = student_id.size();
        vector<int> id(n);
        iota(id.begin(), id.end(), 0);
        vector<int> score(n);
        for (int i = 0; i < n; ++i)
        {
            stringstream ss(report[i]);
            int c = 0;
            string s;
            while (ss >> s)
            {
                if (pf.count(s))
                {
                    c += 3;
                }
                else if (nf.count(s))
                {
                    c -= 1;
                }
            }
            score[i] = c;
        }

        sort(id.begin(), id.end(), [&](int i, int j)
             {
            if(score[i] == score[j])
            {
                return student_id[i] < student_id[j];
            }
            return score[i] > score[j]; });

        vector<int> result;
        for (int i = 0; i < k; ++i)
        {
            result.push_back(student_id[id[i]]);
        }
        return result;
    }
};